package com.gao.interceptors;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器实现接口
 * 可以加注解也可以配置bean
 *
 * @author GaoXi
 * @date 2021/8/17 18:50
 */
@Component
public class FirstInterceptor implements HandlerInterceptor {

    /**
     * Controler之前
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.err.println("FirstInterceptor的preHandler");
        return true;
    }

    /**
     * controller执行后
     *
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.err.println("First-Posthandle");
    }

    /**
     * 页面渲染后
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.err.println("First-afterCompletion");
    }
}
